# $Id$
# Maintainer: Sven-Hendrik Haase <sh@lutzhaase.com>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - removed intel-tbb from deps
#  - set -DUSE_LLVM_BITCODE=OFF for v5 and v6

pkgname=openshadinglanguage
pkgver=1.5.12
pkgrel=7
pkgdesc="Advanced shading language for production GI renderers"
arch=(i686 x86_64)
url="https://github.com/imageworks/OpenShadingLanguage"
license=('custom')
depends=('boost-libs' 'openimageio' 'openexr' 'freetype2' 'libpng'
         'libtiff' 'zlib' 'ncurses')
makedepends=('boost' 'cmake' 'clang35' 'llvm35')
source=(https://github.com/imageworks/OpenShadingLanguage/archive/Release-${pkgver}.tar.gz
        llvm-static-system-libs.patch
        alignment.patch::https://github.com/imageworks/OpenShadingLanguage/commit/bcaf5778e2d778b72615e5c49269b59671cf0d91.patch)
md5sums=('484752a0f97df55962c3a667075deddc'
         'b7c212b2549981ced03c091375f48122'
         'f3f24c2aa7f5aabd98c0967747b58ecc')

prepare() {
  cd OpenShadingLanguage-Release-$pkgver
  patch -Np1 < $srcdir/alignment.patch

  # Add system libraries needed to link against LLVM components (zlib, ncurses)
  # This is required in order to statically link against LLVM
  patch -Np1 < $srcdir/llvm-static-system-libs.patch
}

build() {
  cd OpenShadingLanguage-Release-$pkgver

  cd src

  [[ -d build ]] && rm -r build
  mkdir build && cd build

  [ "${CARCH}" == "arm" -o "${CARCH}" == "armv6h" ] && BITCODE="-DUSE_LLVM_BITCODE=OFF"

  cmake ../.. \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DLLVM_STATIC=1 ${BITCODE} \
    -DSTOP_ON_WARNING=0 \
    -DCMAKE_CXX_FLAGS="-Wno-error=array-bounds -std=c++11"
  make
}

package() {
  cd OpenShadingLanguage-Release-$pkgver/src/build

  make DESTDIR="$pkgdir/" install

  mkdir -p "$pkgdir"/usr/share/OSL/
  mkdir -p "$pkgdir"/usr/share/licenses/$pkgname
  mv "$pkgdir"/usr/LICENSE "$pkgdir"/usr/share/licenses/$pkgname # TODO: Tell upstream about this shit
  mv "$pkgdir"/usr/{CHANGES,README.md,INSTALL} "$pkgdir"/usr/share/OSL/
  mv "$pkgdir"/usr/doc "$pkgdir"/usr/share/OSL/doc
  mv "$pkgdir"/usr/shaders "$pkgdir"/usr/share/OSL/shaders
}

# vim:set ts=2 sw=2 et:
